CPP=gcc

AR=gar
LD=ld
TOBIN=objcopy
DD=dd
SRC = $(wildcard *.S)
PRE_OBJ = $(patsubst %.S, %.s, $(SRC))
OBJ = $(patsubst %.s, %.o, $(PRE_OBJ))
CFLAGS=-E -I../include -I../include/driver
ELFBIN=./../../bin/mbr.elf
BIN=./../../bin/mbr.bin
ASFLAGS+=--32
ifeq ($(DEBUG), ON)
ASFLAGS+=-g
endif

all: $(ELFBIN)

$(ELFBIN): $(OBJ)
	ld -Ttext=0x7c00 -e dragon -melf_i386  -o $@ $^
#	ld -Ttext=0x600 -e dragon -melf_i386  -o $@ $^
	objcopy -O binary $(ELFBIN) $(BIN)
#	ld --oformat binary -Ttext=0x7c5a -e dragon -o $@ $^


$(OBJ): %.o: %.s
	as $(ASFLAGS) -o $@ $<

$(PRE_OBJ): %.s: %.S
	gcc $(CFLAGS) $< -o $@

.PHONY: clean
clean:
	rm -f *.o *.s *.bin $(BIN) $(ELFBIN)
